<?php $this->headScript()
	->appendFile($this->js('jquery-ui/ui/jquery.ui.dialog.js'))
	->appendFile($this->js('jquery-ui/ui/jquery.ui.resizable.js'))
	->appendFile($this->js('jquery-ui/ui/jquery.ui.draggable.js'))
	->captureStart()?>

function upload_dialog(id,name){

	$("#dialog").dialog('open');
	$("#dialog").attr('title','<?php echo $this->translate('uploadSignImage')?> - '+name);
	$("#img_sn").attr('value',id);
	$("#dialog").dialog({
	    modal: true
	});
}


function delimg(id){

   $.ajax({
   type: "POST",
   url: '<?php echo $this->baseScript?>/delimg',
   data: "sn="+id,
   success: function(msg){
     if (msg==1){
     	$("#showimg_"+id).slideUp();
     	$("#delimg_"+id).slideUp();
     }
   }
 });

};

<?php $this->headScript()->captureEnd() ?>


<?php $this->headScript()
	->captureStart() ?>
function del(id,name) {
	if (confirm('<?php echo $this->translate('confirmDelete')?> "'+name+'" ?')){
		document.myform.sn_hidden.value= id;
		document.myform.action='<?php echo $this->baseScript?>/delete';
		document.myform.submit();
		}
	}
	$(document).ready(function(){
	$("#main_body tbody tr:even").addClass('even');
	$("#main_body tbody tr:odd").addClass('odd');
	});
<?php $this->headScript()->captureEnd() ?>
<?php $this->headStyle()->captureStart()?>
#main_body table{background:#ccc;margin:5px auto;width:100%}
#main_body td {padding:3px;}
.even {background:#fff}
.odd {background:#ffc}
.showimg {width:120px;}
<?php $this->headStyle()->captureEnd()?>
<?php $i=0; ?>
<div id="dialog" class="flora" title="<?php echo $this->translate('uploadSignImage')?>" style="display:none;">
<div  style="padding:10px">
<form id="upload" name="uploadform" action='<?php echo $this->baseScript?>/uploadimg' method='post' encType='multipart/form-data'>
<p><input type='file' name='title_img' /></p>
<p><input type='submit' name='act' value='<?php echo $this->translate('uploadSignImage')?>' /></p>
<input type='hidden' id='img_sn' name='img_sn' />
</form>
</div>
</div>

<form name ='myform' action='<?php echo $this->route('index')?>' method='post'>
<div><input type=submit name='act' value='<?php echo $this->translate('browsemode')?>'> <input type=submit name='act' value='<?php echo $this->translate('appendmode')?>'>
<?php if ( isset($_POST['act']) and $_POST['act'] == $this->translate('editmode')): ?>
<input type=submit name='act' value='<?php echo $this->translate('save')?>' onClick="this.form.action='<?php echo $this->baseScript?>/edit';" style='background: yellow'>
<?php else: ?>
<input type=submit name='act' value='<?php echo $this->translate('editmode')?>'>
<?php endif; ?>
</div>
<input type="hidden" name="sn_hidden">
<div id='main_body'>
<table>
	<thead>
	<tr>
	<th><?php echo $this->translate('sort')?></th>
	<th><?php echo $this->translate('name')?></th>
	<th><?php echo $this->translate('name_short')?></th>
	<th><?php echo $this->translate('kind_sn')?></th>
	<th ><?php echo $this->translate('division_sn')?></th>
	<th ><?php echo $this->translate('duty')?></th>
	<?php if ($this->act <>  $this->translate('editmode')): ?>
	<th ><?php echo $this->translate('uploadSignImage')?></th>
	<th align='center'><?php echo $this->translate('act')?></th>
	<?php endif; ?>
	</tr>
	<?php if ($this->act == $this->translate('appendmode')): ?>
	<tr>
	<td><input type="text" name="sort" size="3" /></td>
	<td><input type="text" name="name" size="10" /></td>
	<td><input type="text" name="name_short"  size="10" /></td>
	<td><select name="kind_sn">
		<option value=''></option>
		<?php foreach($this->title_kind as $id=>$val): ?>
		<option value="<?php echo $id?>"><?php echo $val ?></option>
		<?php endforeach ?>
		</select>
		</td>
		<td>

		<select name="division_sn">
		<option value=''></option>
		<?php foreach($this->room_kind as $id=>$val): ?>
		<option value="<?php echo $id?>"><?php echo $val ?></option>
		<?php endforeach ?>
		</select>
		</td>
		<td><input type="text" name="duty"  size="10" /></td>
		<td colspan=2>
		<input type="submit" name="act" value="<?php echo $this->translate('append')?>" onClick="this.form.action='<?php echo $this->baseScript?>/add'" style='background: yellow'>
		<input type="submit" name="act" value="<?php echo $this->translate('cancel')?>" />
		</td>
	</tr>
	<?php endif ?>
	</thead>
	<tbody>
	<?php if ($this->act == $this->translate('editmode')): ?>
	<?php foreach($this->data as $data): ?>
	<tr>
	<td><input type="text" size="2"  name="sort[<?php echo $data['sn'] ?>]"  value="<?php echo $data['sort']?>" /></td>
	<td><input type="text" size="10"  name="name[<?php echo $data['sn'] ?>]" value="<?php echo $data['name'] ?>" /></td>
	<td><input type="text"  size="8" name="name_short[<?php echo $data['sn'] ?>]" value="<?php echo $data['name_short'] ?>"></td>
	<td>
	<select name="kind_sn[<?php echo $data['sn'] ?>]">
		<option value=''></option>
		<?php foreach($this->title_kind as $id=>$val): ?>
		<?php if ($data['kind_sn'] == $id): ?>
		<option value="<?php echo $id?>"  selected><?php echo $val ?></option>
		<?php else:  ?>
		<option value="<?php echo $id?>"><?php echo $val ?></option>
		<?php endif ?>
		<?php endforeach ?>
		</select>
	</td>
	<td>
		<select name="division_sn[<?php echo $data['sn'] ?>]">
		<option value=''></option>
		<?php foreach($this->room_kind as $id=>$val): ?>
		<?php if ($data['division_sn'] == $id): ?>
		<option value="<?php echo $id?>"  selected><?php echo $val ?></option>
		<?php else:  ?>
		<option value="<?php echo $id?>"><?php echo $val ?></option>
		<?php endif ?>
		<?php endforeach ?>
		</select>
	</td>
	<td>
	<input type="text"  size="8" name="duty[<?php echo $data['sn'] ?>]" value="<?php echo $data['duty'] ?>">
	</td>
	</tr>

	<?php endforeach; ?>
	<?php else: ?>
		<?php foreach($this->data as $data): ?>
		<tr class="nom_<?php echo $i++%2+1?>">
		<td align='center'>
		<?php echo $data['sort']?>
		</td>
		<td>
		<?php echo $data['name']?>
		</td>
		<td align='center'>
		<?php echo $data['name_short'] ?>
		</td>
		<td align='center'>
		<?php if ($data['kind_sn']): ?>	<?php echo $this->title_kind[$data['kind_sn']]?><?php endif ?>
		</td>
		<td align='center'>
		<?php if ($data['division_sn']): ?>	<?php echo $this->room_kind[$data['division_sn']]?><?php endif ?>
		</td>
		<td align='center'>
		<?php echo $data['duty']?>
		</td>
		<td align='center'>
		<?php if (is_file($this->store_path.'/title_'.$data['sn'])): ?>
		<img id='showimg_<?php echo $data['sn'] ?>' src="<?php echo $this->baseScript?>/getimg/file/title_<?php echo $data['sn']?>" class="showimg"/>
		<input type='button'  value='<?php echo $this->translate('reUploadSignImage')?>' id="img_<?php echo $data['sn'] ?>"  <?php if ($data['name']):?>onclick="upload_dialog(<?php echo $data['sn'] ?>,'<?php echo $data['name']?>')"<?php else:?>disabled='true'<?php endif ?>  />
		<input type="button"  id='delimg_<?php echo $data['sn'] ?>' value="<?php echo $this->translate('deleteSignImage')?>" onClick="delimg(<?php echo $data['sn']?>)" />
		<?php else:  ?>
		<input type='button'  value='<?php echo $this->translate('uploadSignImage')?>' id="img_<?php echo $data['sn'] ?>"  <?php if ($data['name']):?>onclick="upload_dialog(<?php echo $data['sn'] ?>,'<?php echo $data['name']?>')"<?php else:?>disabled='true'<?php endif ?>  />
		<?php endif; ?>

		</td>
		<td align='center'>
		<input type='button'  value='<?php echo $this->translate('delete')?>' onclick="del(<?php echo $data['sn'] ?>,'<?php echo $data['name'] ?>')"  />
		</td>
			</tr>
	<?php endforeach; ?>
	<?php endif; ?>
	</tbody>
	</table>
	</div>
	</form>
